Dart.Ssh Namespace > SessionStream Class > Read Method : Read(Byte[],Int32,Int32) Method |
'Declaration Public Overloads Overrides Function Read( _ ByVal buffer() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer _ ) As Integer
'Usage Dim instance As SessionStream Dim buffer() As Byte Dim offset As Integer Dim count As Integer Dim value As Integer value = instance.Read(buffer, offset, count)
private void button1_Click(object sender, System.EventArgs e) { //Connect and log into the server. Can be executed on a worker //thread to not block the UI; executed synchronously here for simplicity connectAndLogin(myServerHostname, myServerPort, myUsername, myPassword); //Execute the specified 'receiveData' method on a worker thread to not block the UI ssh1.Start(receiveData, null); } private void connectAndLogin(string hostname, int port, string username, string password) { //Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = hostname; ssh1.Connection.RemoteEndPoint.Port = port; //Usually 22 ssh1.Connect(); //Authenticate SshLoginData loginDetails = new SshLoginData(); loginDetails.Username = username; loginDetails.Password = password; ssh1.Authenticate(loginDetails); } /// <summary> /// Receives data from the server and marshals it to the UI thread for display. /// </summary> /// <param name="notUsed">Not used in this snippet</param> private void receiveData(object notUsed) { //Establish a shell SessionStream session = ssh1.StartShell(); //Receive data when it is sent by the remote host //Marshal it to the UI for display while (true) { byte[] buf = new byte[1024]; Data data = session.Read(buf); //If data.Count is 0, the connection has been closed, so break out of the loop. if (data.Count == 0) break; ssh1.Marshal(data, session, "", null); } } /// <summary> /// Raised on the UI thread, when ssh1.Marshal is called in receiveData. /// </summary> private void ssh1_Data(object sender, SshDataEventArgs e) { textBox1.AppendText(e.Data.ToString()); }
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'Connect and log into the server. Can be executed on a worker 'thread to not block the UI; executed synchronously here for simplicity connectAndLogin(myServerHostname, myServerPort, myUsername, myPassword) 'Execute the specified 'receiveData' method on a worker thread to not block the UI ssh1.Start(AddressOf receiveData, Nothing) End Sub Private Sub connectAndLogin(ByVal hostname As String, ByVal port As Integer, ByVal username As String, ByVal password As String) 'Connect to the server ssh1.Connection.RemoteEndPoint.HostNameOrAddress = hostname ssh1.Connection.RemoteEndPoint.Port = port 'Usually 22 ssh1.Connect() 'Authenticate Dim loginDetails As New SshLoginData() loginDetails.Username = username loginDetails.Password = password ssh1.Authenticate(loginDetails) End Sub ''' <summary> ''' Receives data from the server and marshals it to the UI thread for display. ''' </summary> ''' <param name="notUsed">Not used in this snippet</param> Private Sub receiveData(ByVal notUsed As Object) 'Establish a shell Dim session As SessionStream = ssh1.StartShell() 'Receive data when it is sent by the remote host 'Marshal it to the UI for display Do Dim buf(1023) As Byte Dim data As Data = session.Read(buf) 'If data.Count is 0, the connection has been closed, so break out of the loop. If data.Count = 0 Then Exit Do End If ssh1.Marshal(data, session, "", Nothing) Loop End Sub ''' <summary> ''' Raised on the UI thread, when ssh1.Marshal is called in receiveData. ''' </summary> Private Sub ssh1_Data(ByVal sender As Object, ByVal e As SshDataEventArgs) Handles ssh1.Data textBox1.AppendText(e.Data.ToString()) End Sub